﻿using System.Collections.Generic;

namespace Sidvall.LogManager.Model.DataPortalManagers
{
    public partial class LogScopeManager<TEntity, TList>
    {
        #region Public Members

        #region DeleteItemByPrimaryKeyAsync

        public async System.Threading.Tasks.Task<int> DeleteItemByPrimaryKeyAsync(int serverConnectionId, long applicationId)
        {
            var criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeField>();
            criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.LogManager.Data.Fields.LogScopeField>();
            criteria.Filter.AddFilterItem(global::Sidvall.LogManager.Data.Fields.LogScopeField.LogScopeId, Sidvall.Data.ComparisonOperator.Equal, applicationId);
            ParameterManager.InitializeParameters(criteria, serverConnectionId);

            return await DeleteItemsAsync(criteria).ConfigureAwait(false);
        }

        #endregion
        #region GetItemByPrimaryKeyAsync

        public async System.Threading.Tasks.Task<TEntity> GetItemByPrimaryKeyAsync(int? serverConnectionId, long logScopeId)
        {
            return await GetItemByPrimaryKeyAsync(serverConnectionId, logScopeId, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> GetItemByPrimaryKeyAsync(int? serverConnectionId, long logScopeId, System.Collections.Generic.IEnumerable<global::Sidvall.LogManager.Data.Relations.LogScopeRelation> includedEntities)
        {
            var criteria = Sidvall.Data.CriteriaManager.NewFetchCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeField, global::Sidvall.LogManager.Data.Relations.LogScopeRelation>(null, null, includedEntities, null, null);
            criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.LogManager.Data.Fields.LogScopeField>();
            criteria.Filter.AddFilterItem(global::Sidvall.LogManager.Data.Fields.LogScopeField.LogScopeId, Sidvall.Data.ComparisonOperator.Equal, logScopeId);
            ParameterManager.InitializeParameters(criteria, serverConnectionId);

            return await GetItemAsync(criteria).ConfigureAwait(false);
        }

        #endregion
        #region GetItemAllIncludedAsync

        public async System.Threading.Tasks.Task<TEntity> GetItemAllIncludedAsync(int? serverConnectionId, long logScopeId)
        {
            List<global::Sidvall.LogManager.Data.Relations.LogScopeRelation> includedEntities;

            includedEntities = new List<Data.Relations.LogScopeRelation>();
            includedEntities.Add(Data.Relations.LogScopeRelation.LogScopeItems);

            return await GetItemByPrimaryKeyAsync(serverConnectionId, logScopeId, includedEntities).ConfigureAwait(false);
        }

        #endregion

        #endregion
    }
}